runOnStartup(async runtime => {
    window.addEventListener("minerTick", (e) => {
    })
    window.addEventListener("minerInit", (e) => {
        Hook_shootHook.reacorinitPos()
        Hook_shootHook.shootHock()
    })
});
globalThis.Hook_shootHook = {
    reacorinitPos: function () {
        let minerGameplayer = runtime.objects.point_minerGamePlaye.getFirstInstance()
        if (minerGameplayer == null) return
        let hookInstance = runtime.objects.ToolHook.getFirstInstance()
        Hook_shootHook.hook_init_pos = {
            x: hookInstance.x,
            y: hookInstance.y
        }
    },
    shootHock: function () {
        let maxMoveDistance = 300
        Hook_shootHook.ismove = false
        let minerGameplayer = runtime.objects.point_minerGamePlaye.getFirstInstance()
        if (minerGameplayer == null) return
        let hookInstance = runtime.objects.ToolHook.getFirstInstance()
        if (hookInstance == null) return;
        /**
         * @type {IMoveToBehaviorInstance}
         */
        let moveBehavior = hookInstance.behaviors.MoveTo
        window.addEventListener("Click_Space", (e) => {
            runtime.callFunction("hook_SineDisable")
            let moveX = hookInstance.x + Math.cos(hookInstance.angle) * maxMoveDistance
            let moveY = hookInstance.y + Math.sin(hookInstance.angle) * maxMoveDistance
            if(!hookInstance.isVisible) return
            if (Hook_shootHook.ismove) return
            if (runtime.globalVars.RopeDurability<=0) return;
            moveBehavior.moveToPosition(moveX, moveY, true)
            Hook_shootHook.ismove = true
            runtime.globalVars.RopeDurability-=5
            ConsoleConsoleAddMessage.consoleAddMessage("You used a hook<-->[b] [color=yellow]rope durability - 5[/color]")
            moveBehavior.addEventListener("arrived", async () => {
                if (hookInstance.x === Hook_shootHook.hook_init_pos.x) {
                    return
                }
                var time = setTimeout(function () {
                    moveBehavior.moveToPosition(Hook_shootHook.hook_init_pos.x, Hook_shootHook.hook_init_pos.y, true)
                    setTimeout(() => {
                        runtime.callFunction("hook_SineEnble")
                        var event = new CustomEvent("hookBack", {})
                        window.dispatchEvent(event)
                        Hook_shootHook.ismove = false
                    }, 1500)
                }, 500)
            })
        })
    },
    shootBackSoon: function () {
        var hookInstance = runtime.objects.ToolHook.getFirstInstance()
        var moveBehavior = hookInstance.behaviors.MoveTo
        moveBehavior.moveToPosition(Hook_shootHook.hook_init_pos.x, Hook_shootHook.hook_init_pos.y, true)
        setTimeout(() => {
            runtime.callFunction("hook_SineEnble")
            var event = new CustomEvent("hookBack", {})
            window.dispatchEvent(event)
            Hook_shootHook.ismove = false
        }, 1200)
    }
}
export default Hook_shootHook